package controllers;

import models.KeyBoard;
import models.Student;
import play.mvc.*;

import views.html.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * This controller contains an action to handle HTTP requests
 * to the application's home page.
 */
public class HomeController extends Controller {

    /**
     * An action that renders an HTML page with a welcome message.
     * The configuration in the <code>routes</code> file means that
     * this method will be called when the application receives a
     * <code>GET</code> request with a path of <code>/</code>.
     */
    public Result index() {
        List<KeyBoard> keyBoards = KeyBoard.find.all();
        System.out.println(keyBoards.size());
        Map<String, Integer> collect = keyBoards.stream().collect(Collectors.toMap(item -> item.keyName, item -> item.count, (item1, item2) -> item2));
        return ok(index.render(collect));
    }

}
